
<div class="layui-fluid layui-anim febs-anim" id="febs-hazardType-common" lay-title="调查小组选择" >
    <div class="layui-row layui-col-space8 febs-container" style="height:calc( 100% - 10px)">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12" id="hazardTypeTableContainer" style="height:100%">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" id="hazardType-table-common-form" lay-filter="hazardType-table-common-form">
                        <div class="layui-form-item">
                            <div class="layui-inline febs-hide">
                                <label class="layui-form-label layui-form-label-sm">隐患类型</label>
                                <div class="layui-input-inline" style="width:190px;">
                                    <input type="text" name="status" value="1" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label layui-form-label-sm">隐患类型</label>
                                <div class="layui-input-inline" style="width:190px;">
                                    <input type="text" name="typeName" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div id="query" class="layui-btn">
                                    <i class="layui-icon">&#xe615;</i> 查询
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="jhg-body-table">
                        <table lay-filter="hazardTypeTableCommon" lay-data="{id: 'hazardTypeTable'}"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'commonJS', 'form', 'table', 'febs'], function () {
        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-hazardType-common'),
            $query = $view.find('#query'),
            $searchForm = $view.find('#hazardType-table-common-form'),
            tableIns;

        let tenantId =POPUP_DATA.tenantId;
        let selectList = POPUP_DATA.selectList;
        form.render();

        $view.find("#hazardTypeTableContainer").css("width","100%");

        initTable();
        autoHeight()

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'hazardTypeTableCommon',
                skin: '',
                where:getQueryParams(),
                cols: [[
                    {type: 'radio'},
                    {field: 'typeOperationId', title: '主键', minWidth: 120, hide:true},
                    {field: 'typeName', title: '类型名称', minWidth: 120},
                    {field: 'majorAccidentFlg', title: '事故类型', width: 120,align:'center',templet:function (d) {
                            if(d.majorAccidentFlg == '0'){
                                return '<span class="layui-badge febs-tag-orange">非重大事故</span>'
                            }else{
                                return '<span class="layui-badge febs-tag-red">重大事故</span>'
                            }
                        }},
                    {field: 'sort', title: '排序',align:'center', width: 100},
                    {field: 'remark', title: '备注', minWidth: 120},
                ]],
            });
            tableIns.reload({url: ctx + 'hazardTypeOperation/list', where: getQueryParams(), page: {curr: 1}});
        }


        $query.on('click', function () {
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });


        function getQueryParams() {
            return {
                typeName: $searchForm.find('input[name="typeName"]').val()?.trim(),
                status: $searchForm.find('input[name="status"]').val()?.trim(),
                invalidate_ie_cache: new Date()
            };
        }

        function autoHeight() {
            $view.find('.layui-card').height("100%");
        }

        $(window).resize(function () {
            autoHeight();
        });

        window.getSelectData = function(){
            let selData= table.checkStatus("hazardTypeTableCommon")
            let returnData
            if(selData.data.length>0){
                returnData = {
                    typeOperationId:selData.data[0].typeOperationId,
                    typeName:selData.data[0].typeName,
                    majorAccidentFlg:selData.data[0].majorAccidentFlg,
                }
                if(null != selectList && valueExists(selectList,"typeOperationId",returnData.userId)){
                    returnData = null
                }

            }
            return returnData
        }

        function valueExists (arrayList,fieldName,value){
            let result = $.grep(arrayList,function (e){
                return e[fieldName] == value;
            })
            return result && result.length > 0;
        }
    })
</script>
